package com.twu.biblioteca.app.book;

import com.twu.biblioteca.app.Item;

public class Book extends Item implements Comparable<Book> {
    private String title;
    private String author;


    public Book (String title, String author) {
        super(title);
        this.title = title;
        this.author = author;

    }

    public Book (String title, String author, CheckoutDetails checkoutDetails){
        super(title, checkoutDetails);
        this.title = title;
        this.author = author;
    }

    public String getTitle() {
        return this.title;
    }

    public String getAuthor() {
        return this.author;
    }

    @Override
    public int compareTo(Book other){
        int compareTitle = this.title.compareTo(other.title);
        return compareTitle == 0 ? this.author.compareTo(other.author) : compareTitle;
    }

    @Override
    public boolean equals(Object otherObj) {
        if (otherObj == null) {
            return false;
        }
        if (getClass() != otherObj.getClass()) {
            return false;
        }

        Book otherBook  = (Book) otherObj;
        if (this.title == otherBook.title) {
            return this.author == otherBook.author;
        }
        return false;
    }
}
